package com.cby.leetcode.相向双指针.LC167;

import java.util.Arrays;

/**
 * ClassName: LC167
 * Package: com.cby.leetcode.相向双指针.LC167
 * Description:
 *
 * @Author dhu-bion
 * @Create 2025/9/3 18:58
 * @Version 1.0
 */
public class LC167 {

    public static void main(String[] args){

        Solution solution = new Solution();

        int[] numbers = new int[]{
                2,7,11,15
        };

        Arrays.stream(solution.twoSum(numbers, 9)).forEach(System.out::println);

    }

    static class Solution {
        public int[] twoSum(int[] numbers, int target) {
            int left = 0;
            int right = numbers.length - 1;


            while(true){

                if(numbers[left] + numbers[right] == target){
                    return new int[]{left + 1,right + 1};
                }

                if(numbers[left] + numbers[right] > target){
                    //1.大于，移动上限
                    right --;
                }else if(numbers[left] + numbers[right] < target){
                    //2.小于，移动下限
                    left ++;
                }
            }


        }
    }


}
